package cn.tedu.charging.device.controller;


import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "设备模块")
@RestController
@Slf4j
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;


    // 获取场站信息
    @ApiOperation(value = "获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult<StationInfoVO> getStationInfo(@PathVariable("gunId") Integer gunId) {
        log.debug("获取场站信息，参数：{}", gunId);
        StationInfoVO stationInfoVO = deviceService.getStationInfo(gunId);
        return JsonResult.ok(stationInfoVO, "获取场站信息成功");
    }

    // 更新枪口状态
    @ApiOperation(value = "更新枪口状态")
    @PostMapping ("/status/gun/status/update")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam) {
        log.debug("更新枪口状态，参数：{}", gunStatusUpdateParam);
        Boolean success=deviceService.updateGunStatus(gunStatusUpdateParam);
        return JsonResult.ok(success,"更新枪口状态成功");
    }

    // 根据 位置和半径 获取附件的场站列表
    @ApiOperation(value = "根据 位置和半径 获取附件的场站列表")
    @GetMapping ("/station/near")
    public JsonResult<List<StationInfoVO>> searchNearStations(Double longitude, Double latitude, Double distance){
        log.debug("根据 位置和半径 获取附件的场站列表，参数：经度{}，维度{}，半径{}", longitude, latitude, distance);
        List<StationInfoVO> stationInfoVOS=deviceService.searchNearStations(longitude, latitude, distance);
        return JsonResult.ok(stationInfoVOS,"根据 位置和半径 获取附件的场站列表成功");
    }



}
